package com.dexilaonian.adpter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.dexilaonian.R;
import com.dexilaonian.activity.StoreDetailActivity;
import com.dexilaonian.bean.ContentBean;
import com.dexilaonian.bean.StoreBean;
import com.dexilaonian.view.MyGridView;
import com.dexilaonian.view.StoreGridView;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/5/2.
 */

public class ContentAdapter extends BaseAdapter{

    private final Context mContext;
    private final List<ContentBean> mContentList;
    private int content_id;

    public ContentAdapter(Context context, List<ContentBean> contentList) {
        mContext = context;
        mContentList = contentList;
    }

    @Override
    public int getCount() {
        return mContentList.size();
    }

    @Override
    public Object getItem(int position) {
    return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HodeView hodeView=null;
        if(convertView==null){
            hodeView=new HodeView();
            convertView = View.inflate(mContext, R.layout.contlist, null);
            hodeView.gridView= (StoreGridView) convertView.findViewById(R.id.gridView);
           hodeView.top=(TextView)convertView.findViewById(R.id.top);
            convertView.setTag(hodeView);
        }else{
            hodeView=(HodeView)convertView.getTag();
        }
        content_id = mContentList.get(position).getId();
        final GridViewAdapter adapter = new GridViewAdapter(mContext, mContentList);
        hodeView.gridView.setAdapter(adapter);
        hodeView.gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                Intent intent = new Intent(mContext, StoreDetailActivity.class);
                intent.putExtra("content_id", content_id);
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }


    class HodeView {
        StoreGridView gridView;
        TextView top;
    }
}
